$(function(){
	if(type=='1'){
		$("#titleId").html("添加信用承诺信息");
		//$('#commitmentCodeId').textbox('setValue','');/* 承诺编码*/
		$('#commitmentNameId').textbox('setValue','');/* 承诺名称*/
		/*$('#departmentCodeId').textbox('setValue',''); 部门编码
		$('#departmentNameId').textbox('setValue',''); 部门名称*/
		
		$("#htmlMsgId").val('');//承诺内容
		$("#subButton").val("添加");
	}
	if(type=='2'){
		$("#titleId").html("修改信用承诺信息");
		queryBySysId();
		$("#subButton").val("修改");
	}
})
//根据sysId查询并给修改赋值
function queryBySysId(){
		if(sysId==''){
			return;
		}
		$.ajax({  
			url:'../creditCommitment/queryCreditCommitment',
			type:'post',
			data:{
			"sysId":sysId
			},
			dataType:'json',
			error:function(){
				$.messager.alert("提示","操作异常","error");
			}, 
			success:function(data){
				var list = data.rows;
				if(list==null || list.length==0){
					$.messager.alert("提示","没有获取到数据信息","error");
					return;
				}
				var entity = list[0];
				//$('#commitmentCodeId').textbox('setValue',entity.commitmentCode);/* 承诺编码*/
				$('#commitmentNameId').textbox('setValue',entity.commitmentName);/* 承诺名称*/
				//$('#departmentCodeId').textbox('setValue',entity.departmentCode);/* 部门编码*/
				//$('#departmentNameId').textbox('setValue',entity.departmentName);/* 部门名称*/
				
				$("#htmlMsgId").val(entity.htmlMsg);//承诺内容
			}
		})
}
//添加或修改
function subForm(){
	var htmlMsg =CKEDITOR.instances.htmlMsgId.getData();/* 承诺内容 */
	//var commitmentCode =$("#commitmentCodeId").val().replace(/\s/g, "");/* 承诺编码*/
	var commitmentName =$("#commitmentNameId").val().replace(/\s/g, "");/* 承诺名称*/
	//var departmentCode =$("#departmentCodeId").val().replace(/\s/g, "");/* 部门编码*/
	//var departmentName =$("#departmentNameId").val().replace(/\s/g, "");/* 部门名称*/
	
	/*if(commitmentCode==''){
		$.messager.alert("提示","承诺编码不允许为空","error");
		return;
	}*/
	if(commitmentName==''){
		$.messager.alert("提示","承诺名称不允许为空","error");
		return;
	}
	/*if(departmentCode==''){
		$.messager.alert("提示","部门编码不允许为空","error");
		return;
	}
	if(departmentName==''){
		$.messager.alert("提示","部门名称不允许为空","error");
		return;
	}*/
	var backUrl ='';
	if(type=='1'){
		backUrl = '../creditCommitment/addCreditCommitment';
	}
	if(type=='2'){
		backUrl = '../creditCommitment/updateCreditCommitment';
	}
	$.ajax({  
		url:backUrl,
		type:'post',
		data:{
		"sysId":sysId,
		"htmlMsg":htmlMsg,
		/*"commitmentCode":commitmentCode,*/
		"commitmentName":commitmentName/*,
		"departmentCode":departmentCode,
		"departmentName":departmentName*/
		},
		dataType:'json',
		error:function(){
			$.messager.alert("提示","操作异常","error");
		}, 
		success:function(data){ 
			var row = data.row;
			if(row>=0){
				$.messager.confirm('确认','操作成功',function(r){       
			    	window.returnValue = "success";
					window.close();
					return; 
			});
			}else{
				$.messager.alert("提示","操作失败","error");
			}
		}
	})
}